<?php
session_start();
isLogin();

if(isset($_POST["Submits"])){
	if($_REQUEST['act']=='modify'){
		$sql="update ".$prefix."link set l_name='".$_POST['l_name']."',l_url='".$_POST['l_url']."',l_index=".$_POST['l_index']." where l_id=".$_REQUEST['l_id'];
		if(mysql_query($sql)){
			reload_js("修改成功","index.php?cmd=link");
		}else{
			reload_js("修改失败，原因：程序错误，请联系技术人员进行修改","index.php");
		}
	}else{
		$sql="insert into ".$prefix."link (l_name,l_url,l_index) values('".$_POST['l_name']."','".$_POST['l_url']."',".$_POST['l_index'].")";
		if(mysql_query($sql)){
			reload_js("添加成功","index.php?cmd=link");
		}else{
			reload_js("添加失败，原因：程序错误，请联系技术人员进行修改","index.php");
		}
	}
}

if($_REQUEST['act']=='del'){
	$sql="delete from ".$prefix."link where l_id=".$_REQUEST['l_id'];
	if(mysql_query($sql)){
		reload_js("","index.php?cmd=link");
	}else{
		reload_js("删除失败，原因：程序错误，请联系技术人员进行修改","index.php");
	}
}
?>
<script language="javascript" src="../templates/<?php echo $moban;?>/js/common.js"></script>
<script language="javascript">
changeWebTitle('友情链接管理');
</script>

<div class="ContentRight">
    <div class="ContentRightTop">
      <div class="BarLeft"></div>
      <div class="ContentRightTopText">友情链接管理</div>
      <div class="BarRight"></div>
      <div class="Cal"></div>
    </div>
    <div class="ContentRightBox">
	<form action="" name="linkform" method="post">
      <table width="100%" cellpadding="0" class="Table1" bordercolor="#4ab902" border="1" cellspacing="0">
        <tr>
          <td height="25" align="center">名称</td>
          <td align="center">链接地址</td>
          <td align="center">是否首页显示</td>
          <td align="center">操作</td>
        </tr>
		<?php 
		$result=mysql_query("select * from ".$prefix."link");
		while($arr=mysql_fetch_array($result)){
		?>
        <tr>
          <td width="19%" height="25" align="center"><?php echo $arr['l_name']?></td>
          <td width="52%" align="center">
		  	<a href="<?php echo $arr['l_url']?>" target="_blank"><?php echo $arr['l_url']?></a>		  </td>
          <td width="13%" align="center"><?php if($arr['l_index']){echo "是";}else{echo "否";}?></td>
          <td width="16%" align="center"><a href="<?php echo "?cmd=".$_REQUEST['cmd']."&l_id=".$arr['l_id']."&act=modify"?>">修改</a>&nbsp;<a href="<?php echo "?cmd=".$_REQUEST['cmd']."&l_id=".$arr['l_id']."&act=del"?>" onclick="return confirm('您确认删除该条记录？删除后将不可恢复！');">删除</a></td>
        </tr>
		<?php }
		
		$l_name="";
		$l_url="http://";
		$l_index=true;
		if($_REQUEST['act']=='modify'){
			$result=mysql_query("select * from ".$prefix."link where l_id=".$_REQUEST['l_id']);
			if($arr=mysql_fetch_array($result)){
				$l_name=$arr['l_name'];
				$l_url=$arr['l_url'];
				if($arr['l_index']==0){$l_index=false;}
			}
		}
		?>
        <tr>
          <td height="25" colspan="4" align="right">&nbsp;</td>
        </tr>
        <tr>
          <td height="25" align="right">链接名称：</td>
          <td colspan="3"><input name="l_name" type="text" id="l_name" size="40"  value="<?php echo $l_name?>"/></td>
        </tr>
        <tr>
          <td height="25" align="right">链接地址：</td>
          <td colspan="3"><input name="l_url" type="text" id="l_url" size="40"  value="<?php echo $l_url?>"/>
          必须以http://开头</td>
        </tr>
        <tr>
          <td height="25" align="right">首页显示：</td>
          <td colspan="3"><p>
            <label>
              <input name="l_index" type="radio" value="1" checked="checked" />
              是</label>
            <label>
              <input type="radio" name="l_index" value="0" <?php if(!$l_index){ echo "checked";}?>/>
              否</label>
            <br />
          </p></td>
        </tr>
        <tr>
          <td height="25" align="right">版权所有：</td>
          <td colspan="3"><a href="http://www.fengsh8.com" target="_blank">风尚淘客程序</a></td>
        </tr>
        <tr>
          <td height="25" align="right">&nbsp;</td>
          <td colspan="3">
            <input name="Submits" type="submit" id="Submits" value=" 提  交" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input name="Reset" type="reset" id="Reset" value=" 重 置 " />          </td>
        </tr>
      </table>
	  </form>
    </div>
    <div class="Cal"></div>
  </div>